package com.zyh.controller;

import com.zyh.entity.EnterSchool;
import com.zyh.entity.Student;
import com.zyh.entity.Users;
import com.zyh.service.ESchoolService;
import com.zyh.service.StudentService;
import com.zyh.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.xml.crypto.Data;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
import java.util.Objects;
import java.util.logging.SimpleFormatter;

@Controller
public class WorkerController {
    @Resource
    private StudentService studentService;
    @Resource
    private ESchoolService eSchoolService;
    @Resource
    private UserService userService;
    @RequestMapping("/WdoSave")
    public String WdoSave(@RequestParam("sno")String sno, @RequestParam("healthy")String healthy ,@RequestParam("users.username") String username , EnterSchool eschool){
        Student student=studentService.findStudentBySno(Integer.parseInt(sno));
        Users users=userService.findByUserName(username);
        student.setHealthy(healthy);
        Date entime = new Date();
        eschool.setEnterTime(entime);
        eschool.setSno(student.getSno());
        eschool.setUsername(users.getUsername());
        eschool.setSname(student.getName());
        eschool.setWname(users.getName());
        eschool.setEplace(users.getwPlace());
        studentService.save(student);
        if(Objects.equals(student.getHealthy(), "Y") || Objects.equals(student.getHealthy(), "y")){
            eSchoolService.save(eschool);
            return "workerView/success";
        }else {
            return "workerView/werror";
        }
    }
}
